import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

public class demo02 {
    public static void main(String[] args) throws InterruptedException {
        //针对特殊场景如何通过Selenium API完成：

        //选择checkbox进行勾选
        //page01();

        //frame框架
        //page02();

        //下拉框
        //page03();

        //alert操作
        //page04();

        //上传文件
        page05();
    }

    private static void page05() {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/test_3/src/main/Page/test05.html?_ijt=6umg71g4s4q3hhf9fthr8vcggu&_ij_reload=RELOAD_ON_SAVE");
        webDriver.findElement(By.cssSelector("input")).sendKeys("D:\\111\\Servers\\.project");
    }

    private static void page04() throws InterruptedException {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/test_3/src/main/Page/test04.html?_ijt=fq1svh2q90tk6mqee46vburbhb&_ij_reload=RELOAD_ON_SAVE");
        webDriver.findElement(By.cssSelector("button")).click();
        sleep(3000);
        //alert弹窗
        webDriver.switchTo().alert().dismiss();
        sleep(3000);
        //点击按钮
        webDriver.findElement(By.cssSelector("button")).click();
        //在alert弹窗中输入呵呵
        webDriver.switchTo().alert().sendKeys("呵呵");
        //alert弹窗确认
        sleep(3000);
        webDriver.switchTo().alert().accept();
    }

    private static void page03() {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/test_3/src/main/Page/test03.html?_ijt=ukleet9bsq71uo78pjg5i638kg&_ij_reload=RELOAD_ON_SAVE");
        WebElement webElement=webDriver.findElement(By.cssSelector("#ShippingMethod"));
        Select select=new Select(webElement);
        select.selectByIndex(4);
        //select.selectByValue("12.51");
    }

    private static void page02() throws InterruptedException {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/test_3/src/main/Page/inner.html?_ijt=3itaopq87s70hqqj6fcgcnmflu&_ij_reload=RELOAD_ON_SAVE");
        webDriver.switchTo().frame("f1");
        sleep(3000);
        webDriver.findElement(By.cssSelector("body > div > div > a")).click();
    }

    private static void page01() {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/test_3/src/main/Page/test01.html?_ijt=etlm06qt03asdefs24a5rmv1q3&_ij_reload=RELOAD_ON_SAVE");
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        List<WebElement> webElements=webDriver.findElements(By.cssSelector("input"));
        for (int i = 0; i < webElements.size(); i++) {
            if(webElements.get(i).getAttribute("type").equals("checkbox")){
                webElements.get(i).click();
            }else{
                ;
            }
        }
    }

}
